﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace Framework.Unity
{
    public sealed class ContainerDecorator : IContainer, IContainerRegistration
    {
        private readonly IContainer _container;
        private readonly IDictionary<Type, object> _objectStore = new Dictionary<Type, object>();

        public ContainerDecorator(IContainer container)
        {
            _container = container;
        }

        public object GetA(Type contractType)
        {
            if (_objectStore.ContainsKey(contractType))
                return _objectStore[contractType];

            return _container.GetA(contractType);
        }

        public object GetA(Type contractType, IDictionary arguments)
        {
            return _container.GetA(contractType, arguments);
        }

        public void RegisterAnInstance(Type contractType, object instance)
        {
            _objectStore[contractType] = instance;
        }

        public void RegisterA(Type contractType, Type implementationType)
        {
            throw new NotImplementedException();
        }

        public void RegisterA(Type contractType, Type implementationType, Lifestyle lifestyle)
        {
            throw new NotImplementedException();
        }

        public void RegisterA(Type contractType, Func<object> func)
        {
            throw new NotImplementedException();
        }

        public void Release(object component)
        {
            _container.Release(component);
        }
    }
}